$(function () {
    var token = sessionStorage.getItem("token");
    var money = sessionStorage.getItem("money");
    var channel = sessionStorage.getItem("channel");
    $("#money").html('￥：' + money);
    if (channel == "lakala") {
        $("#channel").html("收款宝");
    } else if (channel == "alipay") {
        $("#channel").html("支付宝");
    } else {
        $("#channel").html("银联");
    }
    var d = {},
        c = {};
    d.token = token;
    d.money = money;
    d.channel = channel;
    d.method = "get_pay_channel";
    c.token = token;
    c.method = "get_finance_url";
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: d,
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var data = result.data.channel;
                var sttr = "";
                for (var i in data) {
                    sttr += '<div class="am-u-sm-12 top"  data-type="' + data[i].channel_type + '" data-pay="' + data[i].pay_name + '"><div style="background: #fff;border-top: 1px solid #B6B5BB;">';
                    sttr += '<span style="font-size: 15px;padding:8px 5px 5px 8px;">' + data[i].pay_name + '</span>';
                    sttr += '<div class="am-u-sm-12" style="background: #fff;border-bottom: 1px solid #B6B5BB;"><div class="am-u-sm-11" style="padding:0 5px 5px 8px;">';
                    sttr += '<div><span style="font-size: 13px;color: #B6B5BB;">限额: 单笔' + data[i].min_money + '元-' + data[i].max_money + '元</span><span style="font-size: 13px;color: #B6B5BB;padding-left: 5%;">结算:' + data[i].accounting_date + '</span></div>';
                    sttr += '<div><span style="font-size: 13px;color: #B6B5BB;">时间: ' + data[i].start_time + '-' + data[i].end_time + '</span><span style="font-size: 13px;color: #B6B5BB;padding-left:20% ;">费率: ' + data[i].fee + '</span></div></div>';
                    sttr += '<div class="am-u-sm-1" style="padding: 0px 0 0 0px;"><img src="img/right123.png" width="15" class="" alt=""/></div></div></div></div>';
                }
                $(".xxq").html(sttr);
                $(".top").click(function () {

                    var channel_type = $(this).attr("data-type");
                    var pay_n = $(this).attr("data-pay");
                    sessionStorage.setItem("pay_n", pay_n);
                    var d = {};
                    d.token = token;
                    d.money = money;
                    d.channel = channel;
                    d.method = "get_payurl";
                    d.channel_type = channel_type;
                    d.phone_system = "web";
                    $.ajax({
                        type: "post",
                        url: "http://www.rice.com/app/api/h5_access",
                        data: d,
                        dataType: "json",
                        success: function (result) {

                            if (result.status == "1") {
                                var data = result.data;
                                console.log(data);
                                sessionStorage.setItem("url1", data.url);
                                if (data.channel == "unionpay") { //银联
                                    location.href = "zhif.html";
                                } else {
                                    location.href = "ewma.html";
                                }

                                if (data.channel == 'lakala') {
                                    alert(result.message);
                                }

                            } else if (result.status == "2") {
                                alert(result.message);
                                location.href = "login.html";
                            } else if (result.status == 3) {
                                location.href = "channels_idCard.html";
                            } else {
                                alert(result.message);
                            }
                        }
                    })
                })
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    });
    $.ajax({
        type: "post",
        url: "http://www.rice.com/app/api/h5_access",
        data: c,
        dataType: "json",
        success: function (result) {
            if (result.status == "1") {
                var data1 = result.data.url;
                console.log(data1);
                $("#rate").attr("href", data1.rate);
            } else if (result.status == "2") {
                alert(result.message);
                location.href = "login.html";
            } else {
                alert(result.message);
            }
        }
    })
})